#pragma strict
var triggered : boolean;
var areaWidth : float;
var areaHeight : float;
var buttonWidth : float;
var buttonHeight : float;
var quitWidth : float;
var quitHeight : float;
var CameraObject : Transform;
var PlayerObject : Transform;
var Spawnpoint : Transform;
var restartClicked : boolean;
var posX : float;
var posY : float;

function Start(){

	posX = ((Screen.width/2));
	posY = ((Screen.height/2));
	
	areaWidth = 186;
	areaHeight = 20;
	buttonWidth = 120;
	buttonHeight = 25;
	quitWidth = 95;
	quitHeight = 25;
	
	restartClicked = false;
	
}

function Update(){
	var cameraSettings = CameraObject.GetComponent(CameraScript);
		
	if(CameraObject.transform.position == (PlayerObject.transform.position + Vector3(0,2,15))){
		cameraSettings.CameraSpeed = 4;
		if(restartClicked){
			PlayerObject.GetComponent(CharacterMotor).enabled = true;
			restartClicked = false;
		}
	}
}

function OnTriggerEnter(other:Collider){
	PlayerObject.GetComponent(CharacterMotor).enabled = false;
	triggered = true;
}

function OnGUI(){

	if(triggered){
		//Restart Button
		GUILayout.BeginArea(Rect((posX - (buttonWidth/2)), (posY + 20), buttonWidth, buttonHeight));
		GUILayout.BeginHorizontal();
		GUILayout.FlexibleSpace();
		if(GUILayout.Button("Restart")){
	    	RestartGame();
	    };
	    GUILayout.FlexibleSpace();
	    GUILayout.EndHorizontal();
	    GUILayout.EndArea();
	    
	    //Quit Button
	    GUILayout.BeginArea(Rect((posX - (quitWidth/2)),(posY + 45),quitWidth,quitHeight));
		GUILayout.BeginHorizontal();
		GUILayout.FlexibleSpace();
		if(GUILayout.Button("Quit Game")){
			CameraObject.GetComponent(CameraScript).menuClicked = true;
		}
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.EndArea();
	    
	    //Label
		GUILayout.BeginArea(Rect((posX - (areaWidth/2)), posY, areaWidth, areaHeight));
		GUILayout.BeginHorizontal();
	    GUILayout.FlexibleSpace();
        GUILayout.Label("YOU ARE WINNER");
        GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.EndArea();
	}
	
}

function RestartGame() {
	
	var cameraSettings = CameraObject.GetComponent(CameraScript);

	triggered = false;
	cameraSettings.CameraSpeed = 20;
	PlayerObject.transform.position = GameObject.Find("Spawnpoint").transform.position;
	restartClicked = true;


}